/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: GameOverScreen.java 602 2010-07-26 18:46:52Z Harry $
 *   $LastChangedDate: 2010-07-26 18:46:52 +0000 (Mon, 26 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.ui.screen;

import battlefield.resource.Graphics;
import battlefield.resource.Music;
import battlefield.ui.component.HomeButton;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;

/**
 *
 * @author Yong Peng
 */
public class GameOverScreen extends Screen implements ActionListener {

    HomeButton backToHome;

    public GameOverScreen(boolean hasWon) {
        initComponents(hasWon);
    }

    private void initComponents(boolean hasWon) {
        ImageIcon newBackImage;
        Image newImage;
        newBackImage = new ImageIcon(hasWon ? Graphics.SCREEN_WIN.getImage() : Graphics.SCREEN_LOOSE.getImage());
        newImage = newBackImage.getImage();
        this.setBackgroundImage(newImage);
        backToHome = new HomeButton();
        backToHome.addActionListener(this);
        add(backToHome);
        validate();
        //Music.WAR_PHASE.stop();
        if (Music.WAR_PHASE.isRunning()) {
            Music.WAR_PHASE.stop();
        }
    }

    /* Begin Region: State Pattern */
    @Override
    public Screen home() {
        getNetwork().stop();
        return new GameMenuScreen();
    }
    /* End Region: State Pattern */

    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(backToHome)) {
            getGUI().home();
        }
    }
}
